﻿Ext.app.BookLoader = Ext.extend(Ext.ux.tree.XmlTreeLoader, {
    processAttributes: function (attr) {
        attr.loaded = true;
        if (attr.id) {
            attr.leaf = true;
            attr.url = "/Payments/Detail/" + attr.id;
        }
    }
});
var treePanel = {
    xtype: 'treepanel',
    id: 'tree',
    region: 'center',
    margins: '2 2 0 2',
    autoScroll: true,
    rootVisible: false,
    root: new Ext.tree.AsyncTreeNode(),

    // Our custom TreeLoader:
    loader: new Ext.app.BookLoader({
        dataUrl: '/Payments/Tree'
    }),
    onSelectNode: function (tree, node) {

    },
    onDeselectNode: function(tree, node) {
        
    },
    listeners: {
        'render': function (tp) {
            var self = this;
            tp.getSelectionModel().on('selectionchange', function (tree, node) {
                if (node && node.leaf) {
                    self.onSelectNode(tree, node);
                } else {
                    self.onDeselectNode(tree, node);
                   
                }
            })
        }
    }
};